function uuid() {
    function s4() {
        return Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1);
    }
    return s4() + s4() + "-" + s4() + "-" + s4() + "-" + s4() + "-" + s4() + s4() + s4();
}
function NUUID(uuid) {
    var hex = uuid.replace(/[{}-]/g, ""); // remove extra characters
    var a = hex.substr(6, 2) + hex.substr(4, 2) + hex.substr(2, 2) + hex.substr(0, 2);
    var b = hex.substr(10, 2) + hex.substr(8, 2);
    var c = hex.substr(14, 2) + hex.substr(12, 2);
    var d = hex.substr(16, 16);
    hex = a + b + c + d;
    var base64 = HexToBase64(hex);
    return new BinData(3, base64);
}


function processCriteria(criteriaLevel3Id){
//criteria level 3
db.CriteriaLevel3.insert({
    _id: criteriaLevel3Id,
    "Name" : "Highest Controversy Level",
    "ShortName" : "",
    "Order" : 136,
    "CriteriaLevel2Id" : NUUID("d5189705-3ac4-dd4e-c9b9-779142760872"),
    "Category" : "Highest Controversy Level"
});

//TemplateCriteria
db.TemplateCriteria.insert({  
    "_id" :NUUID(uuid()),
    "Name" : "Highest Controversy Level-Answer Category",
    "CriteriaEntity" : "ScreeningData",
    "CriteriaEntityField" : "Highest Controversy Level-Answer Category",
    "CriteriaType" : 8.0000000000000000,
    "CriteriaLevel2Id" : NUUID("d5189705-3ac4-dd4e-c9b9-779142760872"),
    "CriteriaLevel3Id" : criteriaLevel3Id,
    "IsScreenable" : true
});

//OldTemplateCriteria
db.OldTemplateCriteria.insert({  
    "_id" : NUUID(uuid()),
    "Name" : "Highest Controversy Level",
    "CriteriaEntity" : "ScreeningData",
    "CriteriaEntityField" : "Highest Controversy Level-Answer Category",
    "Score" : null,
    "TemplateIndicatorNumber" : "",
    "CriteriaLevel2Id" : NUUID("d5189705-3ac4-dd4e-c9b9-779142760872"),
    "CriteriaType" : 8.0000000000000000,
    "FilterId" : null,
    "CompaniesIdsResult" : null,
    "Order" : 136
});   
}

use ClientPlatform
processCriteria(NUUID(uuid()));

//////////////////////////////////////////////
//////////////////////////////////////////////

//rollback inserted data

//use ClientPlatform
//db.CriteriaLevel3.remove({Name : "Highest Controversy Level"})
//db.OldTemplateCriteria.remove({Name: "Highest Controversy Level"})
//db.TemplateCriteria.remove({Name: "Highest Controversy Level-Answer Category"})
 
//use ScreeningDW_B //_A
//db.getCollection('ScreeningData').update(
//   {"Highest Controversy Level-Answer Category": {$exists:1}},
//   { $unset: { "Highest Controversy Level-Answer Category": ""} },
//   { 'multi': true }   )



